package com.itcast.plane.modoule.person.controller;

import com.itcast.plane.modoule.person.domain.Person;
import com.itcast.plane.modoule.person.dto.PersonCreatDTO;
import com.itcast.plane.modoule.person.service.PersonService;
import com.itcast.plane.util.JsonResult;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RestController
@RequestMapping("/person")
public class PersonController {

    @Resource
    private PersonService personService;

    @PostMapping("/add")
    public JsonResult addPerson(@RequestBody PersonCreatDTO creatDTO){
        return personService.addPerson(creatDTO);
    }

    @DeleteMapping("/delete/{id}")
    public JsonResult deletePerson(@PathVariable int id){
        return personService.deletePerson(id);
    }

    @PutMapping("/edit")
    public JsonResult editPerson(@RequestBody Person person){
        return personService.editPerson(person);
    }

    @GetMapping("/getall")
    public JsonResult getAll(@RequestParam int id){
        return personService.getAll(id);
    }
}
